package haiyangwangwork.day12.homework;

public class Demo4 {
//    4、将"this is a test of java"这句话中的每一个单词的首字母变成大写
//   "This Is A Test Of Java"
    public static String replaceMethod(String str){
        char[] chars=str.toCharArray();
        char[] chars1=new char[chars.length+1];
        for (int i=0;i< chars.length+2;i++){
            if (chars[i]>='a'&&chars[i]<='z'){
                if (i==0){
                    chars[i]=(char)(chars[i]-32);
                }
                if (chars[i+1]==32){
                chars[i+2]= (char) (chars[i+2]-32);
//                System.out.print(chars[i+2]);
                }
            }
            chars1[i]=chars[i];
            System.out.print(chars1[i]);
        }
        return "";
    }

    public static void main(String[] args) {
        System.out.println(replaceMethod("this is a test of java"));
    }
}
